/*
 * File     : Library.java
 * Created  : 1 May 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.library;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
 * <p>
 *  Annotates an interface, specifying the name and other details of native
 *  library for direct mapping.
 * </p>
 *
 * @author Matthew Wilson
 */
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE )
@Documented
public @interface Library
{

    /**
     * <p>
     *  Special pseudo-character-set name for the default platform character
     *  set.
     * </p>
     * <p>
     *  This will map to strings using <code>char*</code> in the default
     *  character set.
     * </p>
     */
    String DEFAULT_CHARSET = "##default##";

    /**
     * <p>
     *  Special pseudo-character-set name for the platform's wide character set
     *  set.
     * </p>
     * <p>
     *  On Windows, this will be equivalent to "UTF-16LE".  On Linux, this will
     *  be equivalent to "UTF-32LE".  This will map to strings using
     *  <code>wchar_t</code>.
     * </p>
     */
    String WIDE_CHARSET = "##wide##";

    /**
     * <p>
     *  The name(s) of the library.
     * </p>
     * <p>
     *  The platform-specific prefix and suffix can be omitted.  For example,
     *  "c" will automatically be map to "libc.so" on POSIX platforms.
     * </p>
     * <p>
     *  More than one name can be provided.  The system uses the first library
     *  that can be successfully loaded.
     * </p>
     * <p>
     *  If the name is not set, or is an empty string, all symbols will be
     *  resolved from the current executable.
     * </p>
     *
     * @return the name
     */
    String[] name() default "";

    /**
     * <p>
     *  Whether to mangle the library name to match the platform's conventions.
     * </p>
     * <p>
     *  On Windows, if set, this means ".dll" will be appended; on Linux, if
     *  set, this means prefixing with "lib" and appending ".so".
     * </p>
     *
     * @return <code>true</code> too mangle the name
     */
    boolean mangleName() default true;

    /**
     * <p>
     *  A name prefix for all functions in the library.
     * </p>
     * <p>
     *  This prefix is applied to all names before mangling (if appropriate),
     *  except functions that have an explicit name provided by the
     *  {@link Function} annotation.
     * </p>
     *
     * @return the prefix for all function names
     */
    String functionPrefix() default "";

    /**
     * <p>
     *  A name prefix for all symbols in the library.
     * </p>
     * <p>
     *  This prefix is applied to all names before mangling (if appropriate),
     *  except symbols that have an explicit name provided by the
     *  {@link Symbol} annotation.
     * </p>
     *
     * @return the prefix for all symbol names
     */
    String symbolPrefix() default "";

    /**
     * <p>
     *  The default calling conventions for this library.
     * </p>
     * <p>
     *  The calling convention can be overridden on a per-method basis.
     * </p>
     *
     * @return the calling conventions
     */
    CallingConvention callingConvention() default CallingConvention.PLATFORM_DEFAULT;

    /**
     * <p>
     *  The character set name to use.
     * </p>
     * <p>
     *  By default, the platform character set is chosen.
     * </p>
     *
     * @return the character set name
     */
    String charset() default DEFAULT_CHARSET;

}
